﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json.Linq;

/// <summary>
/// Summary description for JsonFieldExtractor
/// </summary>
public class JsonFieldExtractor
{
	private readonly JObject obj;

	/// <summary>
	/// Constructor
	/// </summary>
	/// <param name="obj">Json object</param>
	public JsonFieldExtractor(JObject obj)
	{
		if (obj == null)
		{
			return;
		}
		this.obj = obj;
	}

	/// <summary>
	/// Returns string value of a field by its name
	/// </summary>
	/// <param name="fieldName">Name of a field</param>
	/// <returns>String value by field's name</returns>
	public string GetFieldStringValue(string fieldName)
	{
		string fieldValue = obj[fieldName].ToString();
		if (String.IsNullOrEmpty(fieldValue))
		{
			return String.Empty;
		}
		return fieldValue;
	}
}